package com.bumptech.glide.request;

import android.graphics.drawable.Drawable;
import android.os.Handler;
import com.bumptech.glide.request.animation.GlideAnimation;
import com.bumptech.glide.request.target.SizeReadyCallback;
import com.bumptech.glide.util.Util;
import java.util.concurrent.CancellationException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

public class RequestFutureTarget<T, R>
  implements FutureTarget<R>, Runnable
{
  private static final Waiter DEFAULT_WAITER = new Waiter();
  private final boolean assertBackgroundThread;
  private Exception exception;
  private boolean exceptionReceived;
  private final int height;
  private boolean isCancelled;
  private final Handler mainHandler;
  private Request request;
  private R resource;
  private boolean resultReceived;
  private final Waiter waiter;
  private final int width;

  public RequestFutureTarget(Handler paramHandler, int paramInt1, int paramInt2)
  {
    this(paramHandler, paramInt1, paramInt2, true, DEFAULT_WAITER);
  }

  RequestFutureTarget(Handler paramHandler, int paramInt1, int paramInt2, boolean paramBoolean, Waiter paramWaiter)
  {
    this.mainHandler = paramHandler;
    this.width = paramInt1;
    this.height = paramInt2;
    this.assertBackgroundThread = paramBoolean;
    this.waiter = paramWaiter;
  }

  private R doGet(Long paramLong)
    throws ExecutionException, InterruptedException, TimeoutException
  {
    try
    {
      if (this.assertBackgroundThread)
        Util.assertBackgroundThread();
      if (this.isCancelled)
        throw new CancellationException();
    }
    finally
    {
    }
    if (this.exceptionReceived)
      throw new ExecutionException(this.exception);
    if (this.resultReceived);
    for (Object localObject2 = this.resource; ; localObject2 = this.resource)
    {
      return localObject2;
      if (paramLong == null)
        this.waiter.waitForTimeout(this, 0L);
      while (Thread.interrupted())
      {
        throw new InterruptedException();
        if (paramLong.longValue() > 0L)
          this.waiter.waitForTimeout(this, paramLong.longValue());
      }
      if (this.exceptionReceived)
        throw new ExecutionException(this.exception);
      if (this.isCancelled)
        throw new CancellationException();
      if (!this.resultReceived)
        throw new TimeoutException();
    }
  }

  public boolean cancel(boolean paramBoolean)
  {
    boolean bool1 = true;
    while (true)
    {
      try
      {
        boolean bool2 = this.isCancelled;
        if (bool2)
          return bool1;
        if (!isDone())
        {
          if (!bool1)
            continue;
          this.isCancelled = true;
          if (paramBoolean)
            clear();
          this.waiter.notifyAll(this);
          continue;
        }
      }
      finally
      {
      }
      bool1 = false;
    }
  }

  public void clear()
  {
    this.mainHandler.post(this);
  }

  public R get()
    throws InterruptedException, ExecutionException
  {
    try
    {
      Object localObject = doGet(null);
      return localObject;
    }
    catch (TimeoutException localTimeoutException)
    {
      throw new AssertionError(localTimeoutException);
    }
  }

  public R get(long paramLong, TimeUnit paramTimeUnit)
    throws InterruptedException, ExecutionException, TimeoutException
  {
    return doGet(Long.valueOf(paramTimeUnit.toMillis(paramLong)));
  }

  public Request getRequest()
  {
    return this.request;
  }

  public void getSize(SizeReadyCallback paramSizeReadyCallback)
  {
    paramSizeReadyCallback.onSizeReady(this.width, this.height);
  }

  public boolean isCancelled()
  {
    try
    {
      boolean bool = this.isCancelled;
      return bool;
    }
    finally
    {
      localObject = finally;
      throw localObject;
    }
  }

  public boolean isDone()
  {
    try
    {
      if (!this.isCancelled)
      {
        boolean bool2 = this.resultReceived;
        if (!bool2);
      }
      else
      {
        bool1 = true;
        return bool1;
      }
      boolean bool1 = false;
    }
    finally
    {
    }
  }

  public void onDestroy()
  {
  }

  public void onLoadCleared(Drawable paramDrawable)
  {
  }

  public void onLoadFailed(Exception paramException, Drawable paramDrawable)
  {
    try
    {
      this.exceptionReceived = true;
      this.exception = paramException;
      this.waiter.notifyAll(this);
      return;
    }
    finally
    {
      localObject = finally;
      throw localObject;
    }
  }

  public void onLoadStarted(Drawable paramDrawable)
  {
  }

  public void onResourceReady(R paramR, GlideAnimation<? super R> paramGlideAnimation)
  {
    try
    {
      this.resultReceived = true;
      this.resource = paramR;
      this.waiter.notifyAll(this);
      return;
    }
    finally
    {
      localObject = finally;
      throw localObject;
    }
  }

  public void onStart()
  {
  }

  public void onStop()
  {
  }

  public void run()
  {
    if (this.request != null)
    {
      this.request.clear();
      cancel(false);
    }
  }

  public void setRequest(Request paramRequest)
  {
    this.request = paramRequest;
  }

  static class Waiter
  {
    public void notifyAll(Object paramObject)
    {
      paramObject.notifyAll();
    }

    public void waitForTimeout(Object paramObject, long paramLong)
      throws InterruptedException
    {
      paramObject.wait(paramLong);
    }
  }
}

/* Location:           C:\Users\user\Desktop\dd28_pcdd720\classes_dex2jar.jar
 * Qualified Name:     com.bumptech.glide.request.RequestFutureTarget
 * JD-Core Version:    0.6.2
 */